<template>
	<view class="container">
		<view class="intro">
			<image src="https://res.uxiao.vip/Utea/logo.png"></image>
			<view class="tips">
				斛鲜“0”负担&nbsp;&nbsp;·&nbsp;&nbsp;信遇新知己
				<br>
				在UTEA遇见两种美好
			</view>
		</view>
		<view class="bottom">
			<!-- #ifdef H5 -->
				<button type="primary" size="default" class="login-btn" @tap="login">
					登录
				</button>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			
				<button type="primary" size="default" class="login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" lang="zh_CN" >
					<!-- <image src="/static/images/mine/wechat.png"></image> -->
					手机号快捷登录
				</button>

			<!-- #endif -->
			<view class="d-flex flex-column justify-content-evenly align-items-center text-center" style="height: 30vh;">
				<view class="w-100 font-size-base text-color-assist">新用户登录即加入会员，享会员权益</view>
				<view class="w-100 row d-flex just-content-around align-items-center font-size-sm text-color-assist">
					<view class="grid">
						<image src="/static/images/mine/rhyl.png"></image>
						<view>入会有礼</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/jfdh.png"></image>
						<view>积分兑换</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/sjtq.png"></image>
						<view>升级特权</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/srtq.png"></image>
						<view>生日特权</view>
					</view>
					<view class="grid">
						<image src="/static/images/mine/nxbz.png"></image>
						<view>UTEA宝藏</view>
					</view>
				</view>
				<!-- <view class="font-size-base text-color-primary">会员权益说明</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	// import Member from '@/api/member'
	import {mapMutations} from 'vuex'
	
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			
		},
		methods: {
			...mapMutations(['SET_MEMBER']),
			async getPhoneNumber(e) {
				console.log(e,12);
				if(e.detail.code){
					uni.showLoading({
						title:"登录中"
					})
					uni.login({
						success: async(res) => {
							await this.login(e.detail.code,res.code)
							
							uni.hideLoading()
						},
						fail: (err) => {
							
						},
						complete: () => {
							
						}
					})		
				}else{
					uni.hideLoading()
				}
				if(e.detail.errMsg == 'getPhoneNumber:fail user deny'){
					uni.showModal({
						title: '提示',
						content: '您取消了授权登录，请重新授权',
						showCancel: false,
						complete() {
							uni.navigateBack()
						}
					})
					
				}
			},
			
			async login(code_phone,code_openid) {
				let res = await this.apiPost("/user/login/mini_phone",{code_phone,code_openid})
				console.log(res);
				if(res.data.code == 1){
					uni.setStorageSync('token',res.data.data.token)
					// this.SET_MEMBER(res.data.data.token)
					this.getUserInfo()
					
				}else{
					this.msg(res.data.msg)
				}
				
			},
			async getUserInfo(){
				let res = await this.apiPost('/user/user/info')
				console.log(res);
				if(res.data.code == 1){
					uni.setStorageSync('userInfo',res.data.data)
					this.SET_MEMBER(res.data.data)
					uni.navigateBack()
				}else{
					uni.showToast({
						title:res.data.msg
					})
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.intro {
		width: 100%;
		height: 60vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-evenly;
		font-size: $font-size-base;
		color: $text-color-assist;
		
		image {
			width: 165rpx;
			height: 165rpx;
		}
		
		.tips {
			line-height: 72rpx;
			text-align: center;
		}
	}
	
	.bottom {
		height: 40vh;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 0 40rpx;
		
		.login-btn {
			width: 100%;
			border-radius: 50rem !important;
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 10rpx 0;
			
			image {
				width: 36rpx;
				height: 30rpx;
				margin-right: 10rpx;
			}
		}
		
		.row {
			.grid {
				width: 20%;
				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>
